﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MediaPortal.DeployTool;

namespace Microsoft.HomeServer.HomeServerConsoleTab.TV4Home.Server.WHS.AddIn.Wizards.InstallTVServer
{
    public partial class WPDatabaseSettingsControl : UserControl
    {
        public WPDatabaseSettingsControl()
        {
            InitializeComponent();
        }

        public void InitializeUI()
        {
            // DB install directory
            if (String.IsNullOrEmpty(InstallationProperties.Instance["DBMSDir"]))
            {
                // set default value for install directory
                if (InstallationProperties.Instance["DBMSType"] == "msSQL2005")
                    this.DBDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + @"\Microsoft SQL Server";
                else
                    this.DBDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + @"\MySQL\MySQL Server 5.1";
            }
            else
            {
                this.DBDirectory = InstallationProperties.Instance["DBMSDir"];
            }

            // DB password
            if (String.IsNullOrEmpty(InstallationProperties.Instance["DBMSPassword"]))
                this.DBUserPassword = "MediaPortal";  // set default value for password
            else
                this.DBUserPassword = InstallationProperties.Instance["DBMSPassword"];

            // DB firewall configuration
            if (String.IsNullOrEmpty(InstallationProperties.Instance["ConfigureDBMSFirewall"]))
                this.ConfigureFirewallDB = true; // set default value for firewall configuration
            else
                this.ConfigureFirewallDB = Convert.ToInt32(InstallationProperties.Instance["ConfigureDBMSFirewall"]) == 1;
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            if (fbdDatabaseDir.ShowDialog() == DialogResult.OK)
            {
                this.DBDirectory = fbdDatabaseDir.SelectedPath;
            }
        }

        public bool ConfigureFirewallDB
        {
            get { return chkConfigureFirewall.Checked; }
            private set { chkConfigureFirewall.Checked = value; }
        }

        public string DBUserPassword
        {
            get { return txtDBServerPassword.Text; }
            private set { txtDBServerPassword.Text = value; }
        }

        public string DBDirectory
        {
            get { return txtDBServerInstallDir.Text; }
            private set { txtDBServerInstallDir.Text = value; }
        }
    }
}
